<template>
  <div id="app">
    <router-view />
  </div>
</template>
<script>
import { mapActions } from 'vuex'
export default {
  data () {
    return {

    }
  },
  mounted () {
    if (this.$cookie.get('userId')) {
      this.getUser()
      this.getCart()
    }
  },
  methods: {
    ...mapActions(['saveUserName', 'saveCartCount']),
    getUser () {
      this.axios.get('/user').then(res => {
        this.saveUserName(res.username)
      }).catch(err => {
        console.log(err)
      })
    },
    getCart () {
      this.axios.get('/carts/products/sum').then(res => {
        this.saveCartCount(res)
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style lang="scss">
@import './assets/scss/reset.scss';
@import './assets/scss/config.scss';
@import './assets/scss/button.scss';
</style>
